package com.example.prison.mapper;

import com.example.prison.entity.AlarmManagement;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【alarm_management】的数据库操作Mapper
* @createDate 2023-05-29 11:14:59
* @Entity com.example.prison.entity.AlarmManagement
*/
@Mapper
public interface AlarmManagementMapper extends BaseMapper<AlarmManagement> {

//    @Select("select * from alarm_management order by id desc")
    @Select("<script>select * from alarm_management " +
            " <where> " +
            " <if test=\"alarmLevel != null and alarmLevel != ''\">and alarm_level like concat('%',#{alarmLevel},'%') </if> " +
            " </where> " +
            "order by id desc</script>")
    List<AlarmManagement> get(@Param("alarmLevel") String alarmLevel);

    @Insert("insert into alarm_management(alarm_level, voltage, color_change, buzzing, splash_screen) " +
            "values (#{alarmLevel}, #{voltage}, #{colorChange}, #{buzzing}, #{splashScreen})")
    int add(AlarmManagement alarm);

    @Delete("<script>delete from alarm_management where id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteAlarm(@Param("ids") Integer[] ids);

    @Update("update alarm_management set alarm_level=#{alarm.alarmLevel}, voltage=#{alarm.voltage}, color_change=#{alarm.colorChange}, buzzing=#{alarm.buzzing}, splash_screen=#{alarm.splashScreen} where id = #{id}")
    int updateAlarm(AlarmManagement alarm,Integer id);

    @Update("update alarm_management set alarm_level=#{alarm.alarmLevel}, voltage=#{alarm.voltage}, color_change=#{alarm.colorChange}, buzzing=#{alarm.buzzing}, splash_screen=#{alarm.splashScreen} where id = #{id}")
    int updateAlarmFail(AlarmManagement alarm,Integer id);

    @Select("select * from alarm_management where alarm_level like concat('%',#{alarmLevel},'%') order by id desc")
    List<AlarmManagement> getLevel(@Param("alarmLevel") String alarmLevel);

    @Select("select * from alarm_management where id=#{id}")
    AlarmManagement getById(@Param("id") Integer id);

    @Select("select * from alarm_management where alarm_level=#{level}")
    AlarmManagement getOneLevel(@Param("level") String level);

}




